package com.scuec.tourismwebsite.mapper;

import com.scuec.tourismwebsite.entity.TouristAttraction;
import org.apache.ibatis.annotations.*;

import java.util.List;
//1
@Mapper
public interface TouristAttractionMapper {
    @Select("SELECT * FROM tourist_attraction")
    List<TouristAttraction> findAll();

    @Select("SELECT * FROM tourist_attraction WHERE attraction_id = #{attractionId}")
    TouristAttraction findById(Integer attraction_id);

    @Select("SELECT city_id FROM city WHERE city_name = #{location}")
    Integer findCityIdByLocation(@Param("location") String location);

    @Insert("INSERT INTO tourist_attraction (city_id, location, attraction_name, short_description, category, opening_hours, entrance_fee,photos, rating, temperature, create_date) VALUES (#{city_id}, #{location},#{attraction_name}, #{short_description}, #{category}, #{opening_hours}, #{entrance_fee}, #{photos},#{rating}, #{temperature}, #{create_date})")
    int insert(TouristAttraction attraction);


    @Delete("DELETE FROM tourist_attraction WHERE attraction_id = #{attraction_id}")
    int delete(Integer attraction_id);

    @Select("SELECT * FROM tourist_attraction WHERE location LIKE CONCAT('%', #{location}, '%')")
    List<TouristAttraction> findByLocation(@Param("location") String location);

    @Select("SELECT * FROM tourist_attraction WHERE attraction_name LIKE CONCAT('%', #{query}, '%') OR location LIKE CONCAT('%', #{query}, '%')")
    List<TouristAttraction> searchByQuery(@Param("query") String query);

    @Select("SELECT * FROM tourist_attraction WHERE attraction_id = #{attraction_id}")
    TouristAttraction findDetailById(@Param("attraction_id") Integer attraction_id);

    @Update("UPDATE tourist_attraction SET photos = #{photos} WHERE attraction_id = #{attraction_id}")
    int updatePhoto(TouristAttraction attraction);

    // 更新基本信息
    @Update("UPDATE tourist_attraction SET city_id = #{city_id}, location = #{location}, rating = #{rating}, attraction_name = #{attraction_name}, short_description = #{short_description}, category = #{category}, opening_hours = #{opening_hours}, entrance_fee = #{entrance_fee} WHERE attraction_id = #{attraction_id}")
    int updateBasicInfo(TouristAttraction attraction);

    // 更新详细信息
    @Update("UPDATE tourist_attraction SET long_description = #{long_description} WHERE attraction_id = #{attraction_id}")
    int updateDetail(TouristAttraction attraction);

    @Update("UPDATE tourist_attraction SET city_id = #{city_id}, rating = #{rating},location = #{location}, attraction_name = #{attraction_name}, short_description = #{short_description}, category = #{category}, opening_hours = #{opening_hours}, entrance_fee = #{entrance_fee} WHERE attraction_id = #{attraction_id}")
    int update(TouristAttraction attraction);
}